﻿@{
    ViewBag.Title = "Dashboard Index";
}

@section head {
    @*<script src="/Scripts/jquery-1.5.1-vsdoc.js" type="text/javascript"></script>*@
    <script type="text/javascript">
        $(document).ready(function () {
            $(".changeTheme").click(function (e) {
                e.preventDefault();
                var url = $(this).attr('href');
                var themeName = $(this).attr('themename');

                $.post(url, ({ themeName: themeName }), function (e) {
                    if (e.result = "success") {
                        window.location.reload();
                    } else {
                        alert("Falha ao alterar tema");
                    }
                });
            });
        });
    </script>
}

<h2>Dashboard Index</h2>

@Html.ActionLink("Ver posts", "Index", "Posts")

<h4>Temas</h4>

<p>
    <strong>Tema atual:</strong> <em>@ViewBag.Conf.Theme.Name</em></p>

    <ul>
    @foreach (var themeName in @ViewBag.Themes)
    {
        <li>@themeName @UseThis(themeName)
        </li>
    }
    </ul>

@functions {
    MvcHtmlString UseThis(string themeName) {
        if (@ViewBag.Conf.Theme.Name != themeName)
            return @Html.ActionLink("Usar este", "ChangeTheme", "Dashboard", null, new { themeName, @class = "changeTheme" });

        return null;
    }
}
